const jwt = require('jsonwebtoken');
const config = require('../config');

module.exports = (req, res, next) => {
    let token = req.headers['x-access-token'];
    let user = req.session.user;
    if (!!user && !!token) {
        jwt.verify(token, config.secret, (err, decoded) => {
            if (err) {
                console.log('jwt--error', err)
                return res.send({ code: 5000, message: '登录失效，请重新登录！' })
            } else {
                next();
            }
        })
    } else {
        res.send({ code: 5000, message: '登录失效，请重新登录！' })
    }
}